package com.ruoyi.ai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai.domain.SysAiTodo;
import com.ruoyi.ai.service.ISysAiTodoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * AI待办Controller
 *
 * @author ruoyi
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/ai/todo")
public class SysAiTodoController extends BaseController
{
    @Autowired
    private ISysAiTodoService sysAiTodoService;

    /**
     * 查询AI待办列表
     */
    @PreAuthorize("@ss.hasPermi('ai:todo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAiTodo sysAiTodo)
    {
        startPage();
        List<SysAiTodo> list = sysAiTodoService.selectSysAiTodoList(sysAiTodo);
        return getDataTable(list);
    }

    /**
     * 导出AI待办列表
     */
    @PreAuthorize("@ss.hasPermi('ai:todo:export')")
    @Log(title = "AI待办", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAiTodo sysAiTodo)
    {
        List<SysAiTodo> list = sysAiTodoService.selectSysAiTodoList(sysAiTodo);
        ExcelUtil<SysAiTodo> util = new ExcelUtil<SysAiTodo>(SysAiTodo.class);
        util.exportExcel(response, list, "AI待办数据");
    }

    /**
     * 获取AI待办详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:todo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysAiTodoService.selectSysAiTodoById(id));
    }

    /**
     * 新增AI待办
     */
    @PreAuthorize("@ss.hasPermi('ai:todo:add')")
    @Log(title = "AI待办", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAiTodo sysAiTodo)
    {
        return toAjax(sysAiTodoService.insertSysAiTodo(sysAiTodo));
    }

    /**
     * 修改AI待办
     */
    @PreAuthorize("@ss.hasPermi('ai:todo:edit')")
    @Log(title = "AI待办", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAiTodo sysAiTodo)
    {
        return toAjax(sysAiTodoService.updateSysAiTodo(sysAiTodo));
    }

    /**
     * 删除AI待办
     */
    @PreAuthorize("@ss.hasPermi('ai:todo:remove')")
    @Log(title = "AI待办", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAiTodoService.deleteSysAiTodoByIds(ids));
    }
}
